<%@ page import="com.jspsmart.upload.SmartUpload" %>
<%@ page import="com.jspsmart.upload.Request" %>
<%@ page import="entity.Users" %>
<%@ page import="entity.Topic" %>
<%@ page import="dao.ITopicDao" %>
<%@ page import="dao.impl.TopicDaoImpl" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/4/4
  Time: 14:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    SmartUpload sm=new SmartUpload();
    sm.initialize(pageContext);
    sm.setCharset("UTF-8");
    sm.upload();
    sm.save("fil");
    Request srt=sm.getRequest();

    String name=srt.getParameter("title");
    Users user= (Users) session.getAttribute("user");
    int id= user.getUid();
    String mcontent=srt.getParameter("mcontent");
    String pic=sm.getFiles().getFile(0).getFileName();
    Topic tc=new Topic(name,mcontent,pic,new Users(id));
    ITopicDao itd=new TopicDaoImpl();
    int b=itd.addPublish(tc);
    if (b>0){
        out.print("<script>alert('添加成功');location.href='main.jsp';</script>");
    }else {
        out.print("<script>alert('添加失败');location.href='main.jsp';</script>");
    }

%>

</body>
</html>
